//
//  Cell_Home.m
//  yjw-winner
//
//  Created by Kae on 2018/9/4.
//  Copyright © 2018年 Shanghai decade financial information service co., LTD. All rights reserved.
//

#import "Cell_Home.h"
#import "JudgeStarsView.h"

@interface Cell_Home () {
    
}
@property (strong, nonatomic) IBOutlet UIView *bgView;

@property (weak, nonatomic) IBOutlet JudgeStarsView *starsView;
@property (weak, nonatomic) IBOutlet UILabel *starsLabel;


@property (weak, nonatomic) IBOutlet UIImageView *bgImageView;
@property (weak, nonatomic) IBOutlet UILabel *courseTypeLabel;
@property (weak, nonatomic) IBOutlet UILabel *listenTimesLabel;
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *userDesLabel;
@property (weak, nonatomic) IBOutlet UILabel *courseDesLabel;
@property (weak, nonatomic) IBOutlet UILabel *priseLabel;

@property (strong, nonatomic) Model_Course *model;
@property (copy, nonatomic) CallBackCellHomeBlock block;
@end
@implementation Cell_Home
/**
 刷新数据并添加回调
 
 @param model model
 @param block block
 */
- (void)refreshWithModel:(id)model addCallBackBlock:(CallBackCellHomeBlock)block {
    self.model = model;
    self.block = block;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil] lastObject];
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 4.0f;

        self.starsView.stars = 4.5;
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
/**
 刷新数据并添加回调
 
 @param model model
 @param block block
 */
- (void)refreshWithModel:(Model_Course *)model CallBackBlock:(CallBackCellHomeBlock)block {
    self.model = model;
    self.block = block;
    [self reloadDataWith:model];
}

/**
 刷新数据

 @param model model
 */
- (void)reloadDataWith:(Model_Course *)model {
    self.userNameLabel.text = model.user_name;
    self.courseTypeLabel.text = model.title;
    self.bgImageView.image = [UIImage imageNamed:model.bg_url];
    self.userDesLabel.text = model.des;
    self.starsView.stars = [model.stars floatValue];
    self.starsLabel.text = model.stars;
    CGFloat price = [model.price floatValue];
    self.priseLabel.text = (price > 0) ? [NSString stringWithFormat:@"%.f元", price] : @"免费";
    self.courseDesLabel.text = model.course_des;
}
#pragma mark --mark EVENT

// 看视频
- (IBAction)lookVedioButtonClick:(UIButton *)sender {
    if (self.block) {
        self.block(self.model, CellHomeButtonTypeVedio);
    }
}

// 听音频
- (IBAction)listonAudioButtonClick:(UIButton *)sender {
    if (self.block) {
        self.block(self.model, CellHomeButtonTypeAudio);
    }
}


@end
